package com.codeyang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codeyang.domain.HotSearch;
import com.codeyang.service.HotSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 描述: TO-删除标志-DO
 *
 * @author CodeYang_Site
 * @version 2021/5/27 10:08
 */
@Api(tags = "热搜管理接口")
@RequestMapping("admin/hotSearch")
@RestController
public class HotSearchController {


    @Autowired
    private HotSearchService hotSearchService;


    @GetMapping("page")
    @ApiOperation("分页查询热搜")
    public ResponseEntity<Page<HotSearch>> page(Page<HotSearch> page, HotSearch hotSearch) {
        Page<HotSearch> hotSearchPage = hotSearchService.page(page, new LambdaQueryWrapper<HotSearch>()
                .eq(!ObjectUtils.isEmpty(hotSearch.getStatus()), HotSearch::getStatus, hotSearch.getStatus())
                .like(!StringUtils.isEmpty(hotSearch.getTitle()), HotSearch::getTitle, hotSearch.getTitle())
                .like(!StringUtils.isEmpty(hotSearch.getContent()), HotSearch::getContent, hotSearch.getContent())
                .orderByDesc(HotSearch::getSeq)
        );
        return ResponseEntity.ok(hotSearchPage);
    }


    @PostMapping
    @ApiOperation("新增热搜")
    public ResponseEntity<Void> test(@RequestBody HotSearch hotSearch) {
        hotSearchService.save(hotSearch);
        return ResponseEntity.ok().build();
    }

}
